<template>
  <div>
    <a-modal
      v-model="finderShow"
      title="模糊查询"
      cancel-text="取消"
      :footer="null"
      @ok="onOK"
      :width="600"
    >
      <a-input style="width: 50%" v-model="searchCondition"></a-input>
      <a-button @click="handleSearch">查询</a-button>
      <vxe-table
        border
        resizable
        show-overflow
        :data="objs"
        ref="xTable"
        size="small"
        highlight-hover-row
      >
        <vxe-table-column type="seq" width="50"></vxe-table-column>
        <vxe-table-column field="business_id" title="点位编号">
          <template #default="{ row }">
            <a @click="onObjClick(row)">{{ row.business_id }}</a>
          </template>
        </vxe-table-column>

        <vxe-table-column field="thing_id" title="id">
          <template #default="{ row }">
            <a @click="onObjClick(row)">{{ row.thing_id }}</a>
          </template>
        </vxe-table-column>
        <vxe-table-column field="s_name" title="设备名称">
          <template #default="{ row }">
            <a @click="onObjClick(row)">{{ row.s_name }}</a>
          </template>
        </vxe-table-column>
        <vxe-table-column field="param_value" title="ip" sortable width="120"></vxe-table-column>
      </vxe-table>
    </a-modal>
  </div>
</template>
<script>
import {rawGet} from '@/services/crud'
export default {
  data() {
    return {
      //value: null,
      finderShow: false,
      fun: null,
      parent: null,
      searchCondition:'',
      objs:[],
    };
  },
  methods: {
    Show(fun, parent) {
      this.fun = fun;
      this.parent = parent;
      this.finderShow = true;
    },
    onOK() {
      if (this.fun) {
        this.fun(this.parent);
        this.finderShow = false;
      }
    },
    handleSearch() {
      let searchCondition = this.searchCondition;
      let query =
        "?olCondition[things.uid]=" +
        "'%25" +
        searchCondition +
        "%25'" +
        "&olCondition[things.s_name]=" +
        "'%25" +
        searchCondition +
        "%25'" +
        "&aeCondition[thing_stations.thing_id]=things.uid" + 
        "&olCondition[thing_params.param_value]=" +
        "'%25" +
        searchCondition +
        "%25'" +
        "&olCondition[things.business_id]=" +
        "'%25" +
        searchCondition +
        "%25'" +
        "&oeCondition[thing_params.param_id]='IP'" +
        "&oeCondition[thing_params.param_id]='UID'";
      let self = this;
      rawGet("/api/queryEx" + query).then((res) => {
        console.log("!!!!!!!!!!!!!", res);

        if (res.data && res.data.result) {
          if (res.data.result.length > 100) {
            this.$warning({
              title: "查询结果过多",
              content: "查询到了超过50条记录，请修改条件重新查询",
            });
            return;
          }
          self.objs = res.data.result;
        }
        else{
          self.objs = []
        }
      });
    },
    onObjClick(row) {
      this.$emit("treesel",row.thing_id, row);
    },
  },
};
</script>